<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>管理员信息修改</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" type="text/css" href="../css/style.css"/>
</head>

<body>
<div id="wrap">
    <div id="top_content">
        <div id="header">
            <div id="rightheader"><p id="current_time">2019-07-11<br/></p></div>
            <div id="topheader"><h1 id="title">学生信息修改</h1></div>
            <div id="navigation"></div>
        </div>
        <div id="content">
            <p id="whereami">
            </p>
            <h1>信息修改</h1>
            <form>
                <table cellpadding="0" cellspacing="0" border="0" class="form_table">
                    <tr>
                        <td valign="middle" align="right">用户名</td>
                        <td valign="middle" align="left">
                            <input id="username" type="text" class="logininput choice" onclick="alert('用户名为学号')" readonly />
                        </td>
                    </tr>
                    <tr>
                        <td valign="middle" align="right">密码</td>
                        <td valign="middle" align="left">
                            <input id="password" type="password" class="logininput" onclick="alert('密码请练习管理员进行修改')" readonly />
                        </td>
                    </tr>
                    <tr>
                        <td valign="middle" align="right">姓名</td>
                        <td valign="middle" align="left">
                            <input id="name" type="text" class="logininput" name="pwd"/>
                        </td>
                    </tr>
                    <tr>
                        <td valign="middle" align="right">电话</td>
                        <td valign="middle" align="left">
                            <input id="phone" type="text" class="logininput"/>
                        </td>
                    </tr>
                    <tr>
                        <td valign="middle" align="right">性别</td>
                        <td valign="middle" align="left">
                            <input type="radio" class="logininput" name="sex" value="男" checked/>男&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="radio" class="logininput" name="sex" value="女"/>女
                        </td>
                    </tr>
                    <tr class="choice">
                        <td valign="middle" align="right">学号</td>
                        <td valign="middle" align="left">
                            <input id="stu_username" type="text" class="logininput" onclick="alert('学号不可以修改')" readonly/>
                        </td>
                    </tr>
                    <tr class="choice">
                        <td valign="middle" align="right">学院</td>
                        <td valign="middle" align="left">
                            <input type="text" class="logininput" id="college"/>
                        </td>
                    </tr>
                    <tr class="choice">
                        <td valign="middle" align="right">专业</td>
                        <td valign="middle" align="left">
                            <input type="text" class="logininput" id="major"/>
                        </td>
                    </tr>
                </table>
                <p>
                    <input type="button" onclick="modify()" class="button" value="确定"/>
                </p>
            </form>
        </div>
    </div>
    <div id="footer">
        <div id="footer_bg">教务处@qq.com</div>
    </div>
</div>
</body>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript">

    let map = {};
    fillCustomMessage();
    fillContent();

    console.log(map);

    // 获取当前日期
    $("#current_time").text(map.time);

    // 读取cookie并写入到map
    function fillCustomMessage() {
        // let map = {}
        let messages = document.cookie.split("; ");
        for (let i = 0; i < messages.length; i++) {
            let ms = messages[i].split("=");
            map[ms[0]] = ms[1];
        }
        $("#footer_bg").text(map.email);
        $("#localdate").text(map.time);
    }

    function fillContent() {
        $.get({
            url: "/modify/getstudent?id=" + map.id,
            success(data) {
                $("#username").val(data.username);
                $("#password").val(data.password);
                $("#name").val(data.name);
                $("#phone").val(data.phone);
                data.sex == "男" ? $('input:radio:first').attr('checked', 'true') : $('input:radio:last').attr('checked', 'true');
                $("#college").val(data.college);
                $("#major").val(data.major);
                $("#stu_username").val(data.username);
            }
        });
    }

    function modify() {
        if (confirm("确认要修改吗?")) {
            $.post({
                url: "/modify/student",
                data: {
                    "id": map.id,
                    "username": $("#username").val(),
                    "password": $("#password").val(),
                    "name": $("#name").val(),
                    "phone": $("#phone").val(),
                    "sex": $("input[name=sex]:checked").val(),
                    "college": $("#college").val(),
                    "major": $("#major").val(),
                }, success(data) {
                    console.log(data);
                    if (data.code == 200) {
                        alert("修改成功");
                        window.location.href = "/login.html"
                    }
                }, error(data) {
                    console.log(data);
                }
            });
        }

    }

</script>
</body>
</html>
